<template>
  <div class="execution">
    <basic-container>
      <avue-crud
        v-model="form"
        v-bind="bindVal"
        v-on="onEvent"
        :page.sync="page"
        :permission="permissionList">
        <template slot="menuLeft">
          <el-button
            type="primary"
            size="small"
            @click="clickOpen"
            >批量修改周期</el-button
          >
        </template>
      </avue-crud>
      <open-dialog
        :DialogVisible.sync="editVisableDialog"
        title="批量修改"
        width="40%"
      >
        <el-form label-width="60px" v-if="editVisableDialog">
          <avue-form
            v-model="formCreate"
            :option="confirmOption"
            style="margin-bottom: 40px"
          ></avue-form>
          <div class="bottom-menu">
            <el-button type="primary" @click="confirmClick()">确认</el-button>
            <el-button type="primary" @click="editVisableDialog = false"
              >取消</el-button
            >
          </div>
        </el-form>
      </open-dialog>
    </basic-container>
  </div>
</template>

<script>
import baseCrud from '@/mixins/base-crud'
import {
  updateMany
} from "@/api/support/swpmlongperiodsettlement";
export default {
  name: 'swpmlongperiodsettlement',
  mixins: [baseCrud('support/swpmlongperiodsettlement')],
  data() {
    return {
      editVisableDialog: false,
      formCreate: {},
    }
  },
  computed: {
    permissionList() {
      return {
        addBtn: this.vaildData(this.permissions.support_sw_pm_long_period_settlement_add, false),
        delBtn: this.vaildData(this.permissions.support_sw_pm_long_period_settlement_del, false),
        editBtn: this.vaildData(this.permissions.support_sw_pm_long_period_settlement_edit, false)
      };
    },
    confirmOption(){
      return {
        emptyBtn: false,
        submitBtn: false,
        column: [{
          type: "select",
          label: "线路",
          prop: "lineCodes",
          props: {
            label: 'name',
            value: 'code'
          },
          filterable: true,
          dicUrl: "/support/swparamline/dict",
          multiple: true,
          rules: [
            {
              required: true,
              message: "请选择一条或多条线路",
            }
          ],
        },	{
          "type": "number",
          "label": "自动结算天数",
          "prop": "settlementTerm",
          "rules": [
            {
              required: true,
              message: "请输入自动结算天数",
              trigger: "blur"
            }
          ],
        }]
      }
    }
  },
  watch: {
    'form.lineCode': {
      handler(val) {
        var lineCode = this.findObject(this.tableOption.column, 'lineCode')
        var stationCode = this.findObject(this.tableOption.column, 'stationCode')
        if (val == 'ALL') {
          lineCode.row = true
          stationCode.display = false
        } else {
          lineCode.row = false
          stationCode.display = true
        }
      },
      immediate: true
    }
  },
  methods: {
    clickOpen(){
      this.editVisableDialog = true;
    },
    confirmClick(){//多修改
    if(this.formCreate.lineCodes == null || this.formCreate.settlementTerm == null){
      this.$message.error("请检查线路和结算天数！")
      return false;
    }
      updateMany(this.formCreate)
        .then(data => {
          this.$message.success('批量修改成功！')
          this.editVisableDialog=false
          this.getList(this.page);
        }).catch(() => {
        }); 
    },
  }
}
</script>
<style lang="scss" scoped>
.bottom-menu {
  margin-top: -30px;
  text-align: center;
}
</style>